package com.example.shiwu.adapter;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;

import com.example.shiwu.ItemInfoEditActivity;
import com.example.shiwu.R;
import com.example.shiwu.db.model.Device;
import com.example.shiwu.db.vo.DeviceVo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class CheckAllAdapter extends BaseAdapter {

    private Context mContext;
    private int resourceId;
    public boolean flage = false;
    private List<DeviceVo> listItems = new ArrayList<DeviceVo>();
    private LayoutInflater mInflater;

    public CheckAllAdapter(Context mContext, List<DeviceVo> listItems, int resource) {
        this.resourceId = resource;
        this.mContext = mContext;
        this.listItems = listItems;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        final ViewHolder viewHolder;
        if (convertView == null) {
            view = LayoutInflater.from(parent.getContext()).inflate(resourceId, parent, false);
            viewHolder = new ViewHolder(view, position);
//            viewHolder.id.setText(listItems.get(position).id);
//            viewHolder.name.setText(listItems.get(position).getName());
//            viewHolder.local.setText(listItems.get(position).getLocation());
//            viewHolder.num.setText(listItems.get(position).getNum());
//            viewHolder.customer.setText(listItems.get(position).getCustomerName());
//            viewHolder.construction.setText(listItems.get(position).getConstructioUnit());
//            viewHolder.type.setText(String.valueOf(listItems.get(position).getDeviceType()));
//            //viewHolder.type.setText("1");
//            viewHolder.operator.setText(listItems.get(position).getOperator());
//            viewHolder.createTime.setText(listItems.get(position).getCreateTime());
            //local,num,customer,construction,type,operator,createTime;
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (CheckAllAdapter.ViewHolder) view.getTag();
        }
//        viewHolder.checkboxOperateData.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                System.out.println("+++++++++++++++++++viewHolder.checkboxOperateData.setOnClickListener++++++++++++++++++++++++++");
//            }
//        });
//        viewHolder.detailsb.setOnClickListener(new View.OnClickListener() {//详情
//            @Override
//            public void onClick(View v) {
//                //Toast.makeText(MyContext, "id === " + v.getId(), Toast.LENGTH_SHORT).show();
//                System.out.println("exportsb =================================== " + v.getId());
//
//            }
//        });
//        viewHolder.exportsb.setOnClickListener(new View.OnClickListener() {//编辑
//            @Override
//            public void onClick(View v) {
//                //Toast.makeText(MyContext, "id === " + v.getId(), Toast.LENGTH_SHORT).show();
//                System.out.println("exportsb =================================== " + v.getId());
//
//            }
//        });
//        viewHolder.delSb.setOnClickListener(new View.OnClickListener() {//删除
//            @Override
//            public void onClick(View v) {
//                System.out.println("id =================================== " + v.getId());
//                //点击删除按钮之后，给出dialog提示
//                AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
//                builder.setTitle("确认删除?");
//                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//                        dialog.dismiss();
//                    }
//                });
//                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//                        System.out.println("id =================================== " + position);
//
//                        Toast.makeText(v.getContext(), "删除成功！", Toast.LENGTH_SHORT).show();
//                    }
//                });
//                builder.show();
//            }
//        });
        //viewHolder.checkboxOperateData = (CheckBox) convertView.findViewById(R.id.device_items_checkbox);
        // 根据isSelected来设置checkbox的显示状况
//        if (flage) {
//            holder.checkboxOperateData.setVisibility(View.VISIBLE);
//        } else {
//            holder.checkboxOperateData.setVisibility(View.GONE);
//        }

        return view;
    }

    @Override
    public int getCount() {
        return listItems.size();
    }

    @Override
    public Object getItem(int position) {
        return listItems.get(position);
    }


    @Override
    public long getItemId(int position) {
        return position;
    }


    class ViewHolder {

        public TextView id,name,local,num,customer,construction,type,operator,createTime,detailsb,exportsb,delSb;
        public CheckBox checkboxOperateData;

        public ViewHolder(View view, int position) {
//            id = view.findViewById(R.id.device_id_val);
//            name = view.findViewById(R.id.device_items_name_val);
//            local = view.findViewById(R.id.device_items_localtion_val);
//            num = view.findViewById(R.id.device_items_num_val);
//            customer = view.findViewById(R.id.device_customer_name_val);
//            construction = view.findViewById(R.id.device_construction_unit_val);
//            type = view.findViewById(R.id.device_type_val);
//            operator = view.findViewById(R.id.device_operator_val);
//            createTime = view.findViewById(R.id.device_items_createTime_val);
//            checkboxOperateData = view.findViewById(R.id.device_items_checkbox);
//            exportsb = view.findViewById(R.id.device_items_export_sb);
//            detailsb = view.findViewById(R.id.device_items_details_sb);
//            delSb = view.findViewById(R.id.device_items_del_sb);
        }

    }

}
